import * as Sequelize from 'sequelize';
import { DataTypes, Model, Optional } from 'sequelize';

export interface noteAttributes {
  id: number;
  title: string;
  content: string;
  carousel?: object;
  status?: number;
  userId?: number;
  like?: number;
  favorite?: number;
  browse?: number;
  topic: object;
  check?: number;
  createdAt?: Date;
  updatedAt?: Date;
}

export type notePk = "id";
export type noteId = note[notePk];
export type noteOptionalAttributes = "id" | "title" | "carousel" | "status" | "userId" | "like" | "favorite" | "browse" | "check" | "createdAt" | "updatedAt";
export type noteCreationAttributes = Optional<noteAttributes, noteOptionalAttributes>;

export class note extends Model<noteAttributes, noteCreationAttributes> implements noteAttributes {
  id!: number;
  title!: string;
  content!: string;
  carousel?: object;
  status?: number;
  userId?: number;
  like?: number;
  favorite?: number;
  browse?: number;
  topic!: object;
  check?: number;
  createdAt?: Date;
  updatedAt?: Date;


  static initModel(sequelize: Sequelize.Sequelize): typeof note {
    return note.init({
    id: {
      autoIncrement: true,
      type: DataTypes.INTEGER.UNSIGNED,
      allowNull: false,
      primaryKey: true,
      comment: "主键ID"
    },
    title: {
      type: DataTypes.STRING(255),
      allowNull: false,
      defaultValue: "",
      comment: "标题"
    },
    content: {
      type: DataTypes.TEXT,
      allowNull: false,
      comment: "内容"
    },
    carousel: {
      type: DataTypes.JSON,
      allowNull: true,
      comment: "轮播图"
    },
    status: {
      type: DataTypes.TINYINT,
      allowNull: true,
      defaultValue: 1,
      comment: "展示状态：0-隐藏,1-正常,默认1"
    },
    userId: {
      type: DataTypes.INTEGER,
      allowNull: true,
      comment: "作者ID"
    },
    like: {
      type: DataTypes.INTEGER,
      allowNull: true,
      defaultValue: 0,
      comment: "点赞数"
    },
    favorite: {
      type: DataTypes.INTEGER,
      allowNull: true,
      defaultValue: 0,
      comment: "收藏数"
    },
    browse: {
      type: DataTypes.INTEGER,
      allowNull: true,
      defaultValue: 0,
      comment: "浏览数"
    },
    topic: {
      type: DataTypes.JSON,
      allowNull: false,
      comment: "话题"
    },
    check: {
      type: DataTypes.INTEGER,
      allowNull: true,
      defaultValue: 1,
      comment: "审核状态：0-待审核，1-通过，2-不通过，默认-0"
    }
  }, {
    sequelize,
    tableName: 'note',
    timestamps: true,
    indexes: [
      {
        name: "PRIMARY",
        unique: true,
        using: "BTREE",
        fields: [
          { name: "id" },
        ]
      },
    ]
  });
  }
}
